package com.hernie.piggymall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Author HuangJp
 * @Date 2022/5/9
 * @Description 订单确认页需要用到的数据
 */
public class OrderConfirmVo {

    // 收货地址，ums_member_recevice_address表
    @Setter @Getter
    List<MemberAddressVo> address;

    // 所有选中的购物项
    @Setter @Getter
    List<OrderItemVo> items;

    // 积分信息
    @Setter @Getter
    Integer integration;

    // 防重令牌
    @Setter @Getter
    String orderToken;

    @Setter @Getter
    Map<Long, Boolean> stocks;

//    BigDecimal tatal; // 订单总额

    public BigDecimal getTatal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

//    BigDecimal payPrice; // 应付价格

    public BigDecimal getPayPrice() {
        return getTatal();
    }


    public Integer getCount() {
        Integer i = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }
}
